package cn.dansj.repository;

import cn.dansj.entity.Menu;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface MenuRepository extends JpaRepository<Menu, String> {
    @Query(value = "select m from Menu m order by m.rn")
    List<Menu> getMenu();

    @Query(value = "select m from Menu m where m.parentId is null order by m.rn")
    List<Menu> getRootMenu();

    @Query(value = "select m from Menu m where m.parentId is null order by m.rn")
    List<Menu> getAllRootMenu();

    @Query(value = "select m from Menu m order by m.rn")
    List<Menu> getAllMenu();

    @Query(value = "select m from Menu m where m.parentId is not null or m.url='/'")
    List<Menu> getSuperAdminMenu();

    @Query(value = "select distinct t1 from Menu t1  inner join RoleMenu t2 on (t1.url = t2.subMenu or t1.url = t2.menu) and t2.permission='1' order by t1.parentId,t1.rn")
    List<Menu> getRoleMenu(@Param("role") String role);
}
